package com.huali.principle.demeter.improve;

import java.util.ArrayList;
import java.util.List;

// 学校总部员工类
class Employee {
    private String id;

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }
}

// 学院员工类
class CollegeEmployee {
    private String id;

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }
}

// 学院管理类
class CollegeManager {
    public List<CollegeEmployee> getAllEmployee() {
        List<CollegeEmployee> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            CollegeEmployee emp = new CollegeEmployee();
            emp.setId("学院员工 id= " + i);
            list.add(emp);
        }
        return list;
    }

    // 新增方法，用于打印学院员工信息，减少 SchoolManager 对 CollegeEmployee 的直接依赖
    public void printCollegeEmployees() {
        List<CollegeEmployee> list = getAllEmployee();
        System.out.println("------------学院员工------------");
        for (CollegeEmployee e : list) {
            System.out.println(e.getId());
        }
    }
}

// 学校管理类
class SchoolManager {
    public List<Employee> getAllEmployee() {
        List<Employee> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Employee emp = new Employee();
            emp.setId("学校总部员工 id= " + i);
            list.add(emp);
        }
        return list;
    }

    // 该方法完成输出学校总部和学院员工信息(id)
    public void printAllEmployee(CollegeManager sub) {
        // 调用 CollegeManager 的打印方法，减少对 CollegeEmployee 的直接访问
        sub.printCollegeEmployees();

        // 获取到学校总部员工
        List<Employee> list2 = this.getAllEmployee();
        System.out.println("------------学校总部员工------------");
        for (Employee e : list2) {
            System.out.println(e.getId());
        }
    }
}

public class DemeterPrinciple {
    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        CollegeManager collegeManager = new CollegeManager();
        schoolManager.printAllEmployee(collegeManager);
    }
}